// Package sysin
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.16.10
package sysin

import (
	"context"
	"hotgo/internal/consts"
	"hotgo/internal/model/entity"
	"hotgo/internal/model/input/form"
	"hotgo/utility/validate"

	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
)

// WxUserUpdateFields 修改小程序用户字段过滤
type WxUserUpdateFields struct {
	NickName  string `json:"nickName"  dc:"用户昵称"`
	AvatarUrl string `json:"avatarUrl" dc:"头像地址"`
	Phone     string `json:"phone"     dc:"手机号"`
	Status    int    `json:"status"    dc:"状态"`
}

// WxUserInsertFields 新增小程序用户字段过滤
type WxUserInsertFields struct {
	NickName  string `json:"nickName"  dc:"用户昵称"`
	AvatarUrl string `json:"avatarUrl" dc:"头像地址"`
	Phone     string `json:"phone"     dc:"手机号"`
	Status    int    `json:"status"    dc:"状态"`
}

// WxUserEditInp 修改/新增小程序用户
type WxUserEditInp struct {
	entity.WxUser
}

func (in *WxUserEditInp) Filter(ctx context.Context) (err error) {
	// 验证用户昵称
	if err := g.Validator().Rules("required").Data(in.NickName).Messages("用户昵称不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证手机号
	if err := g.Validator().Rules("phone").Data(in.Phone).Messages("手机号不是手机号码").Run(ctx); err != nil {
		return err.Current()
	}

	return
}

type WxUserEditModel struct{}

// WxUserDeleteInp 删除小程序用户
type WxUserDeleteInp struct {
	Openid interface{} `json:"openid" v:"required#唯一用户ID不能为空" dc:"唯一用户ID"`
}

func (in *WxUserDeleteInp) Filter(ctx context.Context) (err error) {
	return
}

type WxUserDeleteModel struct{}

// WxUserViewInp 获取指定小程序用户信息
type WxUserViewInp struct {
	Openid string `json:"openid" v:"required#唯一用户ID不能为空" dc:"唯一用户ID"`
}

func (in *WxUserViewInp) Filter(ctx context.Context) (err error) {
	return
}

type WxUserViewModel struct {
	entity.WxUser
}

// WxUserListInp 获取小程序用户列表
type WxUserListInp struct {
	form.PageReq
	NickName string `json:"nickName" dc:"用户昵称"`
	Phone    string `json:"phone"    dc:"手机号"`
	Status   int    `json:"status"   dc:"状态"`
}

func (in *WxUserListInp) Filter(ctx context.Context) (err error) {
	return
}

type WxUserListModel struct {
	Openid      string      `json:"openid"      dc:"唯一用户ID"`
	NickName    string      `json:"nickName"    dc:"用户昵称"`
	AvatarUrl   string      `json:"avatarUrl"   dc:"头像地址"`
	Phone       string      `json:"phone"       dc:"手机号"`
	AccessToken string      `json:"accessToken" dc:"access_token"`
	CreateAt    *gtime.Time `json:"createAt"    dc:"添加时间"`
	UpdateAt    *gtime.Time `json:"updateAt"    dc:"更新时间"`
	Status      int         `json:"status"      dc:"状态"`
}

// WxUserExportModel 导出小程序用户
type WxUserExportModel struct {
	NickName  string      `json:"nickName"  dc:"用户昵称"`
	AvatarUrl string      `json:"avatarUrl" dc:"头像地址"`
	Phone     string      `json:"phone"     dc:"手机号"`
	CreateAt  *gtime.Time `json:"createAt"  dc:"添加时间"`
	Status    int         `json:"status"    dc:"状态"`
}

// WxUserStatusInp 更新小程序用户状态
type WxUserStatusInp struct {
	Openid string `json:"openid" v:"required#唯一用户ID不能为空" dc:"唯一用户ID"`
	Status int    `json:"status" dc:"状态"`
}

func (in *WxUserStatusInp) Filter(ctx context.Context) (err error) {
	if in.Status <= 0 {
		err = gerror.New("状态不能为空")
		return
	}

	if !validate.InSlice(consts.StatusSlice, in.Status) {
		err = gerror.New("状态不正确")
		return
	}
	return
}

type WxUserStatusModel struct{}
